home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
c
/
cserial.zip
/
VT100.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-04-04
|
22KB
|
1,223 lines
/*
* VT100.C
*
* Written for the
*
* Datalight
* Microsoft V 5.x
* TurboC
* &
* Zortech
*
* C Compilers
*
* Copyright (c) John Birchfield 1987, 1988, 1989
*/
#include <stdio.h>
#include <process.h>
#include <ctype.h>
#include "_kb.h"
#include "8250xon.h"
#include "screen.h"
#include "vt100.h"
#if (!defined (TRUE))
# define TRUE (1)
# define FALSE (0)
#endif
char Duplex [2] = { 'F', 0 },
RubOut [2] = { 255, 0 },
BackSpace [2] = { 8, 0 },
Cmask [2] = {127, 0 },
CrLf [2] = { 0, 0 };
#if (defined (STANDALONE))
#include "options.h"
void print_screen_header (void);
main (argc, argv)
int argc;
char *argv [];
{
FILE *fp;
void vt100_driver (), VT100_init ();
set_options (argc, argv);
trap_ctrl_break ();
timer_init ();
xon8250_init (Port, 4096);
fputs ("-- VT100 Terminal Emulator --\n", stdout);
if (Cfg_Str [0])
{
xon8250_port_init (Cfg_Str);
fputs (Opt_Msg, stdout);
}
else
{
xon8250_port_enable ();
fputs ("Default Port Settings Used\n", stdout);
}
fputs ("Use <Alt>F10 to exit, <Alt>F9 to spawn DOS,"
" or <Alt>F8 to Send Break\n", stdout);
screen_init();
print_screen_header ();
rowcol (23, 0);
while (xon8250_timed_read (1) != -1)
;
VT100_init ();
vt100_driver ();
xon8250_term ((Cfg_Str [0])?1:0);
timer_term ();
release_ctrl_break ();
}
void
print_screen_header ()
{
char save = Scr_ATTR;
Scr_ATTR = INVERSE;
rowcol(24,0);
cleol();
rowcol (24, 0);
aputs (INVERSE, "VT100 Emulator");
Scr_ATTR = save;
}
#endif
/*--------------------------------------------------------------------*
| All of the VT100 Specific Stuff Follows |
*--------------------------------------------------------------------*/
void ANSI_MODE (void), CUB (void), CUD (void), CUF (void),
CUP (void), CUU (void), DA (void), DECSTBM (void), DECSC (void),
DECALN (void), DECRC (void), DSR (void), ED (void), EL (void),
RESET (void), RM (void), SGR (void), SM (void), TBC (void),
escA (void), escB (void), escC (void), escD (void), escE (void),
escF (void), escG (void), escH (void), escI (void),
escJ (void), escK (void), escM (void), escY (void), escZ (void);
#define P_MAX 6 /* max no of parameter accumulators */
#define E_BUFF_MAX 11 /* max chars in escape interpreter buffer */
static int save_row, save_col,
save_attr, save_crlf,
initdone = '\0',
tab_stop[80],
special_graphics, ansi_mode,
appl_mode, DECKPNM,
vt_save_attr,
vt_save_row, vt_save_col,
vt_top, vt_bot,
vt_tlim, vt_blim,
vt_row, vt_col,
vt_crlf, vt_org,
vt_wrap, vt_xoff;
char ansi_cursor_set[] = "\\eO%c",
ansi_cursor_reset[] = "\\e[%c",
vt52_cursor[] = "\\e%c",
vt52_kp[] = "\\e?%c",
ansi_kp[] = "\\eO%c",
*kp_sptr, *cursor_sptr;
void vt_putf(char *,...),
vtpf_itoa (int),
vtput_char (char c),
VT_Put_Scr (char),
VT100_Cmd (char),
VT100_KB (char),
VT100_Out (char);
void
vt100_driver ()
{
int chin, chout;
do
{
if (!(vt_xoff) && ((chin = xon8250_read ()) != -1))
if (chin &= *Cmask)
VT100_Cmd (chin);
if ((chout = _kb ()) != -1)
{
switch (chout)
{
case PF5:
tab_stop[vt_col] = TRUE;
break;
case PF6:
tab_stop[vt_col] = FALSE;
break;
case APF8:
xon8250_write_break ();
break;
case APF9:
spawnlp (0, "COMMAND.COM", "COMMAND.COM", (char *) 0);
print_screen_header ();
vt_row = 23; vt_col = 0;
rowcol (vt_row, vt_col);
break;
case APF10:
break;
default:
if (chout != APF1)
VT100_KB (chout);
break;
}
}
} while (chout != APF10);
}
/*--------------------------- VT100_Cmd () ---------------------------*/
/*
*
*/
static int p_ix = 0, p_acc [P_MAX] = { 0 };
static char lastchar = '\0';
void
VT100_Cmd (char ch)
{
if (ch==BS)
{
if (vt_col)
{
rowcol (vt_row,--vt_col);
}
return;
}
if (lastchar && (ch==CAN || ch==SUB))
goto reset;
if (ch==DEL)
return;
switch (lastchar)
{
default:
if (ch==ESC)
{
lastchar = ch;
while (p_ix >= 0)
p_acc [p_ix--] = 0;
p_ix = 0;
return;
}
VT100_Out (ch);
return;
case ESC:
switch (ch)
{
case ESC: return;
case '[':
case '(':
case ')':
case 'Y':
case '#': lastchar = ch; return;
case '7': DECSC (); goto reset;
case '8': DECRC (); goto reset;
case '<': ANSI_MODE (); goto reset;
case '>': DECKPNM = FALSE; goto reset;
case '=': DECKPNM = TRUE; goto reset;
case 'A': escA (); goto reset;
case 'B': escB (); goto reset;
case 'C': escC (); goto reset;
case 'D': escD (); goto reset;
case 'E': escE (); goto reset;
case 'F': escF (); goto reset;
case 'G': escG (); goto reset;
case 'H': escH (); goto reset;
case 'I': escI (); goto reset;
case 'J': ED (); goto reset;
case 'K': EL (); goto reset;
case 'M': escM (); goto reset;
case 'Z': escZ (); goto reset;
case 'c': RESET (); goto reset;
case 'y': goto reset;
default : VT100_Out (ch); goto reset;
}
case '[':
switch (ch)
{
case 'A': CUU (); goto reset;
case 'B': CUD (); goto reset;
case 'C': CUF (); goto reset;
case 'D': CUB (); goto reset;
case 'H':
case 'f': CUP (); goto reset;
case 'J': ED (); goto reset;
case 'K': EL (); goto reset;
case 'c': DA (); goto reset;
case 'g': TBC (); goto reset;
case 'h': SM (); goto reset;
case 'l': RM (); goto reset;
case 'm': SGR (); goto reset;
case 'n': DSR (); goto reset;
case 'q': goto reset;
case 'r': DECSTBM (); goto reset;
case ';': p_ix++;
case '?': return;
default:
if isdigit (ch)
{
p_acc [p_ix] *= 10;
p_acc [p_ix] += (ch-'0');
return;
}
VT100_Out (ch);
goto reset;
}
case '(':
case ')': goto reset;
case '#':
if (ch=='8')
DECALN ();
goto reset;
case 'Y':
p_acc [p_ix++] = ch - 31;
if (p_ix < 2)
break;
else
{
CUP ();
goto reset;
}
}
return;
reset:
lastchar = '\0';
}
/*--------------------------- VT100_Out () ---------------------------*/
/*
*
*/
void
VT100_Out (char ch)
{
switch (ch)
{
case BEL:
putchar (ch);
rowcol (vt_row, vt_col);
break;
case HT:
while (vt_col < 79)
if (tab_stop[++vt_col])
break;
rowcol(vt_row, vt_col);
break;
case DEL:
case ESC:
break;
default:
VT_Put_Scr (ch);
break;
}
}
/*------------------------- VT_Put_Scr () -------------------------*/
/*
*
*/
void
VT_Put_Scr (char ch)
{
static char vt_wrapped = FALSE;
if (vt_wrapped)
{
if (ch == CR)
return;
vt_wrapped = FALSE;
if (ch == LF)
return;
}
if (vt_row > vt_bot)
{
rowcol (vt_row=vt_bot, vt_col);
scroll_up (1, vt_top, 0, vt_bot, 79);
}
switch (ch)
{
case CR:
vt_col = 0;
rowcol (vt_row, vt_col);
if (vt_crlf == FALSE)
break;
case LF:
case VT:
case FF:
if (++vt_row > vt_bot)
scroll_up (1, vt_top, 0, vt_row=vt_bot, 79);
rowcol (vt_row, vt_col);
break;
default:
aput (Scr_ATTR, ch);
if (++vt_col > 79)
{
if (!vt_wrap)
rowcol (vt_row, --vt_col);
else